﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class control_tour_CenterTourDuLich : System.Web.UI.UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }
    }
    protected string GetInfoTitleTour()
    {
        string htmlCode = "";
        string check = "?menu=161&parent=0";
        long idMenu = Convert.ToInt64(Request.QueryString.Get("menu"));
        long idMenucon = Convert.ToInt64(Request.QueryString.Get("id"));
        long idloaihinh = Convert.ToInt64(Request.QueryString.Get("idloaihinh"));
        long idngay = Convert.ToInt64(Request.QueryString.Get("idngay"));
        string tileTour = "";
        if (idMenucon == 0)
        {
            // Get title tour du lịch
            DataTable tenmenu = DataAccess.ExeSQLToDataTable("select name_menu from dev_menu where  idmenu = '" + (idMenu == 0 ? 174 : idMenu) + "'");
            tileTour = tenmenu.Rows[0][0].ToString();
        }
        else
        {
            if (idloaihinh != 0 && idMenucon == -1)
            {
                DataTable tenmenu = DataAccess.ExeSQLToDataTable("select Name from LoaiHinhDuLich where IdDuLich = '" + (idloaihinh == 0 ? 1 : idloaihinh) + "'");
                if (tenmenu.Rows.Count > 0)
                {
                    tileTour = tenmenu.Rows[0][0].ToString();
                }
            }
            if (idngay != 0 && idMenucon == -2)
            {
                DataTable tenmenu = DataAccess.ExeSQLToDataTable("select Name from Ngay where IdDuLich = '" + (idngay == 0 ? 1 : idngay) + "'");
                if (tenmenu.Rows.Count > 0)
                {
                    tileTour = tenmenu.Rows[0][0].ToString();
                }
            }
            else
            {
                DataTable tenmenu = DataAccess.ExeSQLToDataTable("select Name from DiaDanh where IdYahoo = '" + (idMenucon == 0 ? 1 : idMenucon) + "'");
                if (tenmenu.Rows.Count > 0)
                {
                    tileTour = tenmenu.Rows[0][0].ToString();
                }
            }


        }
        htmlCode +=
            "<img src='style/css/img/icon-dulich-trongnuoc.png' /><a>" + tileTour + @" - Du lịch Lanh Đại</a>";
        return htmlCode;

    }
    protected string GetListInfoTour()
    {
        string htmlCode = "";
        long idMenu = Convert.ToInt64(Request.QueryString.Get("menu"));
        long idParent = Convert.ToInt64(Request.QueryString.Get("parent"));
        long idMenucon = Convert.ToInt64(Request.QueryString.Get("id"));
        long idloaihinh = Convert.ToInt64(Request.QueryString.Get("idloaihinh"));
        long idngay = Convert.ToInt64(Request.QueryString.Get("idngay"));
        string link_web = "?menu=" + (idMenu == 0 ? 161 : idMenu) + "&parent=" + (idParent == 0 ? 0 : idParent) + "";
        DataTable tbl = null;
        string tileTour = "";
        if (idMenucon == 0)
        {
            // Get title tour du lịch
            tbl = DataAccess.ExeSQLToDataTable("select * from dev_news where checktour=1 and status = 1 and link_web = '" + link_web + "' order by idnews desc");
        }
        else
        {
            if (idloaihinh != 0 && idMenucon == -1)
            {
                tbl = DataAccess.ExeSQLToDataTable("select * from dev_news where checktour=1 and status = 1 and loaihinhdulich = '" + idloaihinh + "' order by idnews desc");
            }
            else
            {
                if (idngay != 0 && idMenucon == -2)
                {
                    tbl = DataAccess.ExeSQLToDataTable("select * from dev_news where checktour=1 and status = 1 and thoigian = '" + idngay + "' order by idnews desc");
                }
                else
                {
                    tbl = DataAccess.ExeSQLToDataTable("select * from dev_news where checktour=1 and status = 1 and diemden= '" + (idMenucon == 0 ? 1 : idMenucon) + "'");
                }
            }

        }
        foreach (DataRow dr in tbl.Rows)
        {
            htmlCode +=
                @"<div class='div_content_center_tour_khung'>
                    <input type='hidden' id='totalrow' value='"+tbl.Rows.Count+@"'>
                    <div class='img-daidien_tour'>
                        <img src='files_upload/images/pictour/" + dr["picture"] + @"' />
                    </div>
                    <div class='noidung_tour_short'>
                       <div class='name_tour'>
                            <a href='chitiettourdulich.aspx?id=" + dr["idnews"] + @"'><b>" + ITNLip.CatChuoi(dr["title"].ToString(), 80) + @"</b></a>
                        </div>
                        <div class='list_info_tour'>
                            <ul>
                                <li>
                                    <b>Điểm xuất phát: </b><a>" + GetNameDiaDiemById(dr["diemxuatphat"] == null ? 0 : Convert.ToInt64(dr["diemxuatphat"])) + @"</a>
                                </li>
                                <li>
                                    <b>Điểm đến: </b><a>" + GetNameDiaDiemById(dr["diemden"] == null ? 0 : Convert.ToInt64(dr["diemden"])) + @"</a>
                                </li>
                                <li>
                                    <b>Thời gian: </b><a>" + LoadInfoThoigian(dr["hangbay"] == null ? 0 : Convert.ToInt64(dr["thoigian"])) + @"</a>
                                </li>
                                <li>
                                    <b>Phương tiện: </b><a>" + dr["phuongtien"] + @"</a>
                                </li>
                                <li>
                                    <b>Giá tour: </b><a class='giakm'>" + (String.Format("{0:0,0}", dr["giatour"])) + @" VNĐ</a>
                                </li>
                                <li>
                                    <b>Hotline: </b><a class='style_a_hotline'>" + dr["hotline"] + @"</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class='btn_Xemchitiet'>
                        <div class='style_like_face'>
                            <div class='fb-like' data-href='http://lanhdaitourist.com/chitiettourdulich.aspx?id=" + dr["idnews"] + @"' data-send='true' data-layout='button_count'
                                data-show-faces='true'>
                            </div>
                        </div>
                        <a class='style_btnDattour' href='dattourdulich.aspx?id=" + dr["idnews"] + @"' >Đặt tour</a>
                        <a class='style_btnXemtour' href='chitiettourdulich.aspx?id=" + dr["idnews"] + @"'>Xem tour</a>
                    </div>
                </div>";
        }
        return htmlCode;
    }

    protected string GetNameDiaDiemById(long id)
    {
        DataTable dt = DataAccess.ExeSQLToDataTable("select Name from DiaDanh where IdYahoo = '" + id + "'");
        if (dt.Rows.Count == 0)
        {
            return "";
        }
        else
        {
            return dt.Rows[0][0] == null ? "" : dt.Rows[0][0].ToString();
        }

    }
    protected string LoadInfoThoigian(long id)
    {
        string result = "";
        DataTable list =
           DataAccess.ExeSQLToDataTable("select Name from Ngay where IdDuLich=" + id + "");
        if (list.Rows.Count > 0)
        {
            result = list.Rows[0][0].ToString();
        }
        return result;
    }
}